package org.rsbot.loader.script.adapter;

import org.rsbot.loader.asm.ClassAdapter;
import org.rsbot.loader.asm.ClassVisitor;
import org.rsbot.loader.asm.MethodVisitor;
import org.rsbot.loader.script.CodeReader;

public class AddMethodAdapter extends ClassAdapter
{
  private Method[] methods;

  public AddMethodAdapter(ClassVisitor paramClassVisitor, Method[] paramArrayOfMethod)
  {
    super(paramClassVisitor);
    this.methods = paramArrayOfMethod;
  }

  public void visitEnd() {
    for (Method localMethod : this.methods) {
      MethodVisitor localMethodVisitor = this.cv.visitMethod(localMethod.access, localMethod.name, localMethod.desc, null, null);
      localMethodVisitor.visitCode();
      new CodeReader(localMethod.code).accept(localMethodVisitor);
      localMethodVisitor.visitMaxs(localMethod.max_stack, localMethod.max_locals);
      localMethodVisitor.visitEnd();
    }
    this.cv.visitEnd();
  }

  public static class Method
  {
    public int access;
    public String name;
    public String desc;
    public byte[] code;
    public int max_stack;
    public int max_locals;
  }
}